package com.mapresso.mio1;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.util.StringTokenizer;

import javax.imageio.*;

public class Mio1 {

	public Mio1() {
		// Create an image to save
		RenderedImage rendImage = myCreateImage();

		// Write generated image to a file
		try {
			// Save as PNG
			File file = new File("mio1.png");
			ImageIO.write(rendImage, "png", file);

/*			// Save as JPEG
			file = new File("newimage.jpg");
			ImageIO.write(rendImage, "jpg", file);
*/		} catch (IOException e) {
		}

		// Returns a generated image.
	}

	/**
	 * @param args
	 */

	public RenderedImage myCreateImage() {
		int width = 1200;
		int height = 1000;
		// Create a buffered image in which to draw
		BufferedImage bufferedImage = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);

		// Create a graphics contents on the buffered image
		Graphics2D g2d = bufferedImage.createGraphics();

		try {
			BufferedReader in = new BufferedReader(
					new FileReader("shknatiyx.txt"));
			String s = null;
			int bfs, x, y, kate;
			for (int i = 0; i < width * height; i++) {
				s = in.readLine();
				StringTokenizer st = new StringTokenizer(s, "\t");
				try {
					bfs = Integer.parseInt(st.nextToken());
					x = Integer.parseInt(st.nextToken());
					y = Integer.parseInt(st.nextToken());
					kate = Integer.parseInt(st.nextToken());
					if ((i+1) % 1000 == 0) {
						System.out .print(".");
						if ((i+1) % 100000 == 0) System.out .println();
					}
					int xx = i % width;
					int yy = i / width;
					int key = kate / 10;
					Color c;
					switch (key) {
					case 810:
						c = Color.WHITE;
						break;
					case 822:
						c = Color.blue;
						break;
					default:
						c = Color.white;
						break;
					}
//					switch (key) {
//					case 81:
//						c = Color.WHITE;
//						break;
//					case 82:
//						c = Color.red;
//						break;
//					case 83:
//						c = Color.blue;
//						break;
//					case 84:
//						c = Color.green;
//						break;
//					case 85:
//						c = Color.yellow;
//						break;
//					case 86:
//						c = Color.black;
//						break;
//
//					default:
//						c = Color.gray;
//						break;
//					}
					g2d.setColor(c);
					g2d.fillRect(xx, yy, 1, 1);

				} catch (NumberFormatException e) {
				}
			}
			in.close();
		} catch (IOException e) {
			System.err.println(e);
		}
		g2d.dispose();
		System.out.println("end.");

		return bufferedImage;
	}

	public static void main(String[] args) {
		Mio1 mio1 = new Mio1();
	}

}
